<?php
include_once BONE_ROOT.DS.APP_DIR.DS.'templates'.DS.'menu'.DS.'menu.php';

class template_listing extends template_menu
{

	protected function head()
	{
	$menu_list = $this->get('menu_list');
	?>
	<script type="text/javascript" language="javascript" src="templates/menu/js/listing.js"></script>
	<script type="text/javascript" language="javascript">
	var g_oMenuChain = new Object();
	var g_iMenuChainHead = 0;
	<?php
	
	if(count( $menu_list ))
	{
		// 构造双向链表保存菜单项， 方便 JS 查找.
		$pre_id = 0;
		$this_id = 0;
		$next_id = 0;
		
		$menu = null;
		foreach($menu_list as $m)
		{
			if($menu)
			{
				$pre_id = $this_id;
				$this_id = $menu->id;
				$next_id = $m->id;
				echo 'g_oMenuChain["'.$menu->id.'"]={"pre_id":'.$pre_id.',"next_id":'.$next_id.',"id":'.$menu->id.',"name":"'.$menu->name.'","parent_id":'.$menu->parent_id.',"level":'.$menu->level.',"children":'.$menu->children.'};'."\r\n";
			}
			else
				echo 'g_iMenuChainHead = '.$m->id.";\r\n";
			$menu = $m;
		}
		echo 'g_oMenuChain["'.$menu->id.'"]={"pre_id":'.$this_id.',"next_id":0,"id":'.$menu->id.',"name":"'.$menu->name.'","parent_id":'.$menu->parent_id.',"level":'.$menu->level.',"children":'.$menu->children.'};'."\r\n";
	}
	?>
	</script>
	<?php
	}
	
	protected function center()
	{
		$group = $this->get('group');
		$menu_list = $this->get('menu_list');

		$this->toolbar();
		?>

<div class="box">
	<div class="box-tl"><div class="box-tr"><div class="box-tm"></div></div></div>	
	<div class="box-m">
		
		<h3 class="title"><?php echo $this->get_title(); ?></h3>
		
		<form action="./" method="post">
		<table class="list-table">
		
		<thead>
		<tr>
			<th width="80">添加子菜单</th><th width="30">收起</th><th>名称</th><th width="300">连接到应用</th><th width="150">连接到网址</th><th width="30">上移</th><th width="30">下移</th><th width="40">删除</th>
		</tr>
		</thead>
		
		<tbody id="row-list">
		<?php 
		foreach($menu_list as $menu)
		{
		?>
		<tr id="row-<?php echo $menu->id; ?>"  onMouseOver="this.className='row-on'" onMouseOut="this.className='row-off'">
		<td align="center"><a href="javascript:;" onclick="javascript:addSubMenu(<?php echo $menu->id; ?>)" class="add"></a></td>
		<td align="center">
		<?php
		echo '<a href="javascript:;" id="toggle-'.$menu->id.'" onclick="javascript:togleSubMenu('.$menu->id.')" class="toggle-on"';
		if(!$menu->children)
		{
			echo ' style="display:none;"';
		}
		echo '></a>';
		?>
		</td>
		<td>
		<?php
		if($menu->level)
		{
			echo str_repeat('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ', $menu->level);
			echo '|_ ';
		}
		?>
		<input type="hidden" name="id[]" id="id-<?php echo $menu->id; ?>" value="<?php echo $menu->id; ?>" />
		<input type="hidden" name="parent_id[]" id="parent_id-<?php echo $menu->id; ?>" value="<?php echo $menu->parent_id; ?>" />
		<input type="text" name="name[]" id="name-<?php echo $menu->id; ?>"  value="<?php echo $menu->name; ?>" size="20" maxlength="120" />
		</td>
		<td align="center">
			<input type="text" name="m_controller[]" id="controller-<?php echo $menu->id; ?>"  value="<?php echo $menu->controller; ?>" size="10" maxlength="120" />
			<input type="text" name="m_task[]" id="task-<?php echo $menu->id; ?>"  value="<?php echo $menu->task; ?>" size="10" maxlength="120" />
			<input type="text" name="param[]" id="param-<?php echo $menu->id; ?>"  value="<?php echo $menu->param; ?>" size="15" maxlength="120" />
		</td>
		<td align="center"><input type="text" name="url[]" id="url-<?php echo $menu->id; ?>"  value="<?php echo $menu->url; ?>" size="20" maxlength="120" /></td>
		<td align="center"><a href="javascript:;" onclick="javascript:orderUp(<?php echo $menu->id; ?>)" class="order-up-on" id="order-up-<?php echo $menu->id; ?>"></a></td>
		<td align="center"><a href="javascript:;" onclick="javascript:orderDown(<?php echo $menu->id; ?>)" class="order-down-on" id="order-down-<?php echo $menu->id; ?>"></a></td>
		<td align="center"><a href="javascript:;" onclick="javascript:confirmDeleteMenu(<?php echo $menu->id; ?>)" class="delete"></a></td>
		</tr>		
		<?php
		}
		?>
		</tbody>
		
		<tfoot>
		<tr>
			<td><input type="button" value="添加新菜单" onclick="javascript:addSubMenu(0)"/></td>
			<td colspan="7">
			<div class="align-left"><input type="submit" value="保存" /></div>
			</td>
		</tr>
		</tfoot>
		</table>
		<input type="hidden" name="group_id" value="<?php echo $group->id; ?>" />
		<input type="hidden" name="controller" value="menu" />
		<input type="hidden" name="task" value="listing_save" />
		</form>
		<p>
		<ul>
		<li>* 一些模板不能显示多级菜单. </li>
		<li>* 设置连接到网址后， 连接到应用将失效.</li>
		</ul>
		</p>
		
	</div>
	<div class="box-bl"><div class="box-br"><div class="box-bm"></div></div></div>
</div>
		

		<?php
		
	}	

}
?>